package cn.assumejson.springframework.aop.aspectj;

import cn.assumejson.springframework.aop.Pointcut;
import cn.assumejson.springframework.aop.PointcutAdvisor;
import cn.hutool.core.util.ObjectUtil;
import org.aopalliance.aop.Advice;

/**
 * Aspectj 表达式切入点 访问者
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/2 15:08
 */
public class AspectJExpressionPointcutAdvisor implements PointcutAdvisor {

    /**
     * 切面
     */
    private AspectJExpressionPointcut pointcut;

    /**
     * 具体的拦截方法
     */
    private Advice advice;

    /**
     * 切点表达式
     */
    private String expression;

    @Override
    public Advice getAdvice() {
        return this.advice;
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }

    @Override
    public Pointcut getPointcut() {
        if (ObjectUtil.isNull(pointcut)) {
            this.pointcut = new AspectJExpressionPointcut(expression);
        }
        return pointcut;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }
}
